package 笔试;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class jd {

         /*
         江北衫zdhq
                * 两个有序连表合并一个链表
                */
    public static void main(String[] args) {
        ListNode l1 = new ListNode(1);
        ListNode l2 = new ListNode(2);
        ListNode l11;
        ListNode l22;
        l11=l1;
        l22=l2;
        l1.next=new ListNode(4);
        l1=l1.next;
        l1.next=new ListNode(7);
        l1=l1.next;
        l1.next=new ListNode(9);
        l1=l1.next;
        l1.next=new ListNode(11);
        l1=l1.next;
        l1.next=new ListNode(14);
        l1=l1.next;
        l1.next=new ListNode(18);

        l2.next=new ListNode(5);
        l2=l2.next;
        l2.next=new ListNode(7);
        l2=l2.next;
        l2.next=new ListNode(13);
        l2=l2.next;
        l2.next=new ListNode(15);
        l2=l2.next;
        l2.next=new ListNode(24);
        l2=l2.next;
        l2.next=new ListNode(34);
        l2=l2.next;
        l2.next=new ListNode(44);
        l2=l2.next;
        l2.next=new ListNode(54);


        jd j = new jd();
        ListNode l =j.mergeTwoLists(l11,l22);
        while (l!=null){
            System.out.println(l.val);
            l=l.next;
        }


        /**
         * /**
         * * Definition for singly-linked list.
         * * public class ListNode {
         * * int val;
         * * ListNode next;
         * * ListNode() {}
         * * ListNode(int val) { this.val = val; }
         * * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
         * * }
         * */

    }

    private static void q() {
        Scanner cin = new Scanner(System.in);
        int n=cin.nextInt();//n个商店
        int m=cin.nextInt();//买m个宝石
        for (int i=0;i<n;i++){

        }//每个商店 第一次买的价格
        for (int i=0;i<n;i++){

        }//每个商店 之后买的价格
    }

       public  ListNode mergeTwoLists (ListNode l1, ListNode l2){
           ListNode listNode;
           ListNode begin;
           if(l1.val<l2.val){
               listNode = new ListNode(l1.val);
               l1=l1.next;
           }else {
               listNode = new ListNode(l2.val);
               l2=l2.next;
           }
           begin=listNode;
           while(l1!=null||l2!=null){
               if(l1==null){
                   listNode.next=new ListNode(l2.val);
                   l2=l2.next;
               }else if(l2==null){
                   listNode.next=new ListNode(l1.val);
                   l1=l1.next;
               }else{
                   if(l1.val> l2.val){
                       listNode.next=new ListNode(l2.val);
                       l2=l2.next;
                   }else{
                       listNode.next=new ListNode(l1.val);
                       l1=l1.next;
                   }
               }
               listNode=listNode.next;
           }
           return begin;
       }

    private static void jd001() {
        Scanner cin = new Scanner(System.in);
        int n=cin.nextInt();
        int[] a = new int[n];
        int min=0,max=0;
        for (int i = 0; i < n; i++) {
            a[i] = cin.nextInt();
            if(a[i]<a[min]){min=i;}
            if(a[i]>a[max]){max=i;}

        }
        if(n<3){System.out.println(0);return;}
        if(max<min){
            int k=max;
            max=min;
            min=k;
        }
        if(n==3){
            if(min!=0||max!=2){
                System.out.println(1);
            }else{
                System.out.println(2);
            }
            return;
        }
        if(n==4){
            if(min==1&&max==2){
                System.out.println(2);
                return;
            }
        }
        int k1=0,k2=0,k31=10000,k32=10000,k33=10000;//k1表示--》     k2表示《--       k3表示--》    《--
        for(int i=0;i<n;i++){
            if(a[i]==a[min]){
                k1|=1;
                if(k31>i){
                    k31=i;
                }
            }
            if(a[i]==a[max]){
                k1|=2;
                if(k32>i){
                    k32=i;
                }
            }
            if(k1==3){k1=i+1;break;}
        }
        for(int i=n-1;i>=0;i--){
            if(a[i]==a[min]){k2|=1;
                if(a[i]==a[k31]){
                    k33=Math.min(k33,n-i+k32+1);
                }else {
                    k33=Math.min(k33,n-i+k31+1);
                }
            }
            if(a[i]==a[max]){k2|=2;
                if(a[i]==a[k31]){
                    k33=Math.min(k33,n-i+k32+1);
                }else {
                    k33=Math.min(k33,n-i+k31+1);
                }
            }
            if(k2==3){k2=n-i;break;}
        }

        System.out.println(Math.min(Math.min(k1, k2), k33));
//        System.out.println(Math.min(Math.min(max + 1, n - min), min + 1 + n - max));
        return;
    }

    public int distributeCandies(int[] candyType) {
        Set<Integer> set = new HashSet<>();
        for(int i:candyType)
            set.add(i);

        if(candyType.length/2>set.size()){
            return candyType.length/2;
        }else {
            return set.size();
        }
    }
}
